package in.co.codedoc.user;

import in.co.codedoc.cg.annotations.HasProperties;
import in.co.codedoc.cg.annotations.IsAnIOCComponent;
import in.co.codedoc.cg.annotations.IsMappedToJSON;
import in.co.codedoc.cg.annotations.Property;
import in.co.codedoc.cg.annotations.ShortType;
import in.co.codedoc.config.Configurable;
import in.co.codedoc.config.ConfigurationUtil;
import in.co.codedoc.json.JSONValue;

import java.util.Random;

@IsAnIOCComponent
@HasProperties
({
	@Property(name="numVolumes",datatype=ShortType.class),
	@Property(name="numSubVolumes",datatype=ShortType.class),
	@Property(name="volumesRoot",datatype=String.class)
})
@IsMappedToJSON
public class UserVolumeGenerator
	extends UserVolumeGeneratorBase
	implements Configurable
{
	public UserVolumeGenerator()
	{
		SetNumVolumes((short)100);
		SetNumSubVolumes((short)1000);
		SetVolumesRoot("/var/my-secretary/volumes");
	}
	
	public String GenerateVolume()
	{
		int volume = random.nextInt(GetNumVolumes());
		int subVolume = random.nextInt(GetNumSubVolumes());
		
		return Integer.toString(volume) + "/" + Integer.toString(subVolume);
	}

	private static final Random random = new Random(System.currentTimeMillis());

	@Override
	public void Configure(JSONValue json)
	{
		ConfigurationUtil.ConfigureUsingProperties(this,json);
	}

	@Override
	public String GetConfigSectionName()
	{
		return "UserLocations";
	}
	
}
